package com.pro.common.api.statics.user.amount.model.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pro.common.api.model.BaseUserModel;
import com.pro.common.api.model.dto.UserAmountKey;
import com.pro.framework.api.FrameworkConst;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.math.BigDecimal;
import java.util.Map;
import java.util.function.Function;

/**
 * 数额变化的基础类
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class AmountEntity extends BaseUserModel implements IAmountEntity {
    @Schema(description = "数额类型")
    private String amountType;

    @Schema(description = "当前数量")
    private BigDecimal amount;

    @Schema(description = "本日增加数额")
    private BigDecimal todayIncreaseAmount;
    @Schema(description = "历史增加数额")
    private BigDecimal totalIncreaseAmount;


    @Override
    public String getEntityKey() {
        return getAmountType() + FrameworkConst.Str.split_pound + getUserId();
    }

    @Override
    public void setEntityKey(String key) {
        setAmountType(key.split(FrameworkConst.Str.split_pound)[0]);
        setUserId(Long.valueOf(key.split(FrameworkConst.Str.split_pound)[1]));
    }

    public UserAmountKey toKey() {
        return new UserAmountKey(this.getUserId(), this.getAmountType());
    }

    @Schema(description = "更变前的初始值当前数额")
    transient private BigDecimal amountChangeInit;
    @Schema(description = "更变前的初始值当前数额")
    transient private Map propMap;

    public <T> Map<String, Function<T,Object>> getPropMap() {
        return propMap;
    }
}
